import { GoodsDescPage } from "../../uiScript/dressUp/GoodsDescPage";
import { MCommonAwardTipPage } from "../common/MCommonAwardTipPage";
import { MCommonTipPage } from "../common/MCommonTipPage";
import { GameContextEventMgr } from "../GameContextEventMgr";
import { GameEventCenter } from "../GameEventCenter";
import { LableCfg } from "../obj/GlobalObj";
import { PGCServer } from "../PGCServer";
import { SceneMgr } from "../SceneMgr";
import { GameTool } from "../tool/GameTool";
import { LotteryDataMgr } from "./data/LotteryDataMgr";
import { MLotteryClotheAwardTipPage } from "./MLotteryClotheAwardTipPage";

export class MLotteryClothePage {


    private _dataMgr: LotteryDataMgr;

    private static _ins: MLotteryClothePage;
    static get Ins(): MLotteryClothePage {
        return this._ins ||= new MLotteryClothePage();
    }

    open() {
        SceneMgr.open(SceneMgr.LotteryClothePage, false);
    }


    public get dataMgr() {
        return this._dataMgr ||= new LotteryDataMgr();
    }

    getListSuitLuckyBox(callback: Laya.Handler): void {
        this.dataMgr.getListSuitLuckyBox(callback);
    }

    getListGoodsInSuitLuckyBox(id: number, callback: Laya.Handler) {
        this.dataMgr.getListGoodsInSuitLuckyBox(id, callback);
    }



    clickLottery(suit: any, callback: Laya.Handler) {
        MCommonTipPage.openSp([
            { top: 86, labelCfgs: [new LableCfg("消耗", 26), new LableCfg("200", 26, "#C8102E"), new LableCfg("水晶，", 26)] },
            { top: 118, labelCfgs: [new LableCfg("可抽一次限量妆扮哦！", 26)] }
        ], null, Laya.Handler.create(this, () => {
            this.dataMgr.buyAndOpenSuitLuckyBox(suit.define_id, Laya.Handler.create(this, (data: any) => {
                if (data && data.length) {
                    // reward_img_url: "", reward_desc: "" 
                    let arr = (<Array<any>>data).map((item: any) => {
                        return { iconUrl: PGCServer.ins.formatUrl(item.goods_icon_url), desc: item.goods_desc };
                    });
                    MCommonAwardTipPage.open(arr);
                    // MLotteryClotheAwardTipPage.Ins.open(arr);
                    data[0] && GameContextEventMgr.sendGlobalEvent("narsReportData", ["suit_draw", { suit_name: data[0].goods_name, draw_result: "抽奖成功" }]);
                }
                else {
                    GameTool.tips("没有抽中任务物品");
                    GameContextEventMgr.sendGlobalEvent("narsReportData", ["suit_draw", { draw_result: "抽奖失败" }]);
                }
                callback && callback.run();
            }));
        }));
    }

    close() {
        this._dataMgr = null;
        SceneMgr.close(SceneMgr.LotteryClothePage);
    }
}